import { observable, action } from 'mobx';

class FormStore {

    @observable addonBeforeMap = [];
    @observable is_ajax = 0;

    @action setAjax(is_ajax){
        this.is_ajax = is_ajax;
    }

    @action getAjax(){
        return this.is_ajax;
    }

    @action reload(that){
        if(this.is_ajax){
            // 接口一般两百毫秒得到数据，得到数据后再渲染一次
            setTimeout(function () {
                that.forceUpdate();
            },250)
        }
    }

    @action setFieldAddonBefore(field,addonBefore){
        this.addonBeforeMap[field] = addonBefore;
        console.log("setFieldAddonBefore",field,addonBefore,this.addonBeforeMap)
    }

    @action getFieldAddonBefore(field,addonBefore){
        console.log("getFieldAddonBefore",field,addonBefore);
        if(this.addonBeforeMap[field]){
            return this.addonBeforeMap[field]
        }
        return addonBefore;
    }
}

export default new FormStore()